<html>
<head><meta charset="utf-8"><title>Name classification and namespaces · t-compiler/rust-analyzer · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/index.html">t-compiler/rust-analyzer</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html">Name classification and namespaces</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="224359886"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224359886" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224359886">(Jan 28 2021 at 17:14)</a>:</h4>
<p>Name classification seems to have a "small" problem. We don't classify names correctly if they exist in multiple namespaces,  see <a href="https://github.com/rust-analyzer/rust-analyzer/issues/7408">https://github.com/rust-analyzer/rust-analyzer/issues/7408</a> and <a href="https://github.com/rust-analyzer/rust-analyzer/issues/7479">https://github.com/rust-analyzer/rust-analyzer/issues/7479</a> for examples</p>



<a name="224360038"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224360038" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224360038">(Jan 28 2021 at 17:15)</a>:</h4>
<p>Basically if a name appears in multiple namespaces we seem to resolve it in the macro, type and then value namespace in that order. So if we find a name in the macro namespace for example we immediately return it and therefor skip going through the type and value namespace even if we actually want the type behind the name.</p>



<a name="224360268"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224360268" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224360268">(Jan 28 2021 at 17:17)</a>:</h4>
<p>On the other hand maybe we just need some more <code>ast</code> matches to fix these two occurences up, I haven't looked at classification too much yet. Actually for semantic highlighting issue I think its just missing a check ye, but the other issue seems a bit more problematic?</p>



<a name="224362041"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224362041" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224362041">(Jan 28 2021 at 17:29)</a>:</h4>
<p>So I think <code>classify_**name**</code> should always just return a definition, as the namespaces can be inferred from the def itself</p>



<a name="224362160"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224362160" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224362160">(Jan 28 2021 at 17:29)</a>:</h4>
<p>for <strong>name_ref</strong>, yeah, those can be genuinely multinamespaced</p>



<a name="224362283"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224362283" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224362283">(Jan 28 2021 at 17:30)</a>:</h4>
<p>but I think only in actual uses? <code>use serde::Sedialize</code> is both a macro and a trait</p>



<a name="224362623"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224362623" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224362623">(Jan 28 2021 at 17:32)</a>:</h4>
<p>So I think we need to do two things:</p>
<ul>
<li>fix the bugs -- those two issues seem like we just return the wrong thing</li>
<li>change the interface to account for multple namespaces. This'll go as far as the editor showing a multiresolve dialog for uses</li>
</ul>



<a name="224363071"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224363071" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224363071">(Jan 28 2021 at 17:35)</a>:</h4>
<p>As for fixing the actual bugs, I think they might be related to <a href="https://github.com/rust-analyzer/rust-analyzer/issues/3407">https://github.com/rust-analyzer/rust-analyzer/issues/3407</a></p>



<a name="224365049"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224365049" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224365049">(Jan 28 2021 at 17:46)</a>:</h4>
<p>Yes only use statements should have multinamespaced NameRefs I believe.</p>



<a name="224365145"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224365145" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224365145">(Jan 28 2021 at 17:47)</a>:</h4>
<p>The bugs do seem related to that issue, which looks like a quite tough one.</p>



<a name="224365697"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224365697" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> matklad <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224365697">(Jan 28 2021 at 17:50)</a>:</h4>
<p><span class="user-mention" data-user-id="300586">@Lukas Wirth</span> you have a talent for poking at "we need to rewrite the underlying abstraction" issues in rust-analyzer ) This is sooo helpful!)</p>



<a name="224365962"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224365962" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224365962">(Jan 28 2021 at 17:52)</a>:</h4>
<p><span aria-label="sweat smile" class="emoji emoji-1f605" role="img" title="sweat smile">:sweat_smile:</span></p>



<a name="224368557"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/185405-t-compiler/rust-analyzer/topic/Name%20classification%20and%20namespaces/near/224368557" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Lukas Wirth <a href="https://rust-lang.github.io/zulip_archive/stream/185405-t-compiler/rust-analyzer/topic/Name.20classification.20and.20namespaces.html#224368557">(Jan 28 2021 at 18:11)</a>:</h4>
<p>Without looking too much into the rest, the function calls being shadowed by types was simple to fix <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7483">https://github.com/rust-analyzer/rust-analyzer/pull/7483</a> we were indeed simply missing a check here <a href="https://github.com/rust-analyzer/rust-analyzer/pull/7483/files#diff-0da7dd327a598aadb8c360d534aedf26f76c26b5a877a6a543649323509e3aecR236-R238">https://github.com/rust-analyzer/rust-analyzer/pull/7483/files#diff-0da7dd327a598aadb8c360d534aedf26f76c26b5a877a6a543649323509e3aecR236-R238</a></p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>